<template>
  <div class="ding-box">
    <div class="ding-login">
      <transition name="el-fade-in-linear">
        <div class="login-logo" v-loading="loading">
          <img v-lazy="img" alt="">
          <p>{{$t('login.slogan')}}</p>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
import { ERR_OK } from '@/api/options/statusCode'
import {getDingTalkValidate} from '@/api/dingTalk'
import logo from '@/commom/default/bpm.jpg'
import DingtalkEnv from 'dingtalk-javascript-env'
import LoginMxin from '@/commom/mixins/loginMixin'
import {setToken, setUserInfo, setAppName} from '@/utils/auth'
export default {
  name: 'DingtalkMsg',
  mixins: [LoginMxin],
  data() {
    return {
      img: logo,
      loading: false,
      appcode: ''
    }
  },
  created() {
    this.appcode = this.$route.params.appcode
  },
  mounted() {
    // 钉钉自动登录
    if (DingtalkEnv.isDingTalk) {
      this.loading = true
      const url = this.baserApi
      this.getDingTalkInfo(url)
    }
  },
  methods: {
    // 权限验证
    getDingTalkAppValidate(option) {
      let that = this
      return new Promise((resolve, reject) => {
        getDingTalkValidate(option).then((res) => {
          that.loading = false
          if (res.code === ERR_OK) {
            const data = res.data
            console.log(data, '获取权限验证--------')
            if (data.PortalRoot == null) {
              window.localStorage.setItem('H3.PortalRoot', '/Portal')
            } else {
              window.localStorage.setItem('H3.PortalRoot', data.PortalRoot)
            }
            setToken(data.MobileUser.ObjectID)
            setUserInfo({name: data.MobileUser.Name, id: data.MobileUser.ObjectID, userCode: data.MobileUser.Code, ParentID: data.MobileUser.parentID})
            const code = this.appcode
            // console.log(code, 'code--------')
            that.$router.push({
              path: '/appcenter/child'
            })
            setAppName({name: code, code: code})
          }
          resolve(res)
        }).catch(error => {
          that.loading = false
          reject(error)
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  @import "../../commom/scss/mixin";
  @import "../../commom/scss/varible";
  .ding-box{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .ding-login {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .login-logo {
      padding-bottom: 2rem;
      p {
        font-size: 1rem;
        line-height: 2rem;
        color: $textColor;
        padding: 0 10px;
        text-align: center;
        white-space: normal;
      }
      img {
        width: 6.5rem;
        height: 6.5rem;
      }
    }
  }
</style>
